package parttern.singleton;

import parttern.singleton.SingleInstanceEnum;
import parttern.singleton.SingleInstanceHungry;
import parttern.singleton.SingleInstanceInner;
import parttern.singleton.SingleInstanceLazy;

public class SingleInstanceDoubleCheck {

    private SingleInstanceDoubleCheck() {

    }

    private volatile static SingleInstanceDoubleCheck instance;

    public static SingleInstanceDoubleCheck getInstance() {
        if (null == instance) {
            synchronized (SingleInstanceDoubleCheck.class) {
                if (null == instance) {
                    instance = new SingleInstanceDoubleCheck();
                }
            }
        }

        return instance;
    }

    public void show() {
        System.out.println("SingleInstanceDoubleCheck show():" + this.hashCode());
    }

    ///test
    public static void main(String[] args) {
        SingleInstanceDoubleCheck.getInstance().show();
        SingleInstanceDoubleCheck.getInstance().show();
        SingleInstanceEnum.INSTANCE.show();
        SingleInstanceEnum.INSTANCE.show();
        SingleInstanceHungry.getInstance().show();
        SingleInstanceHungry.getInstance().show();
        SingleInstanceInner.getInstance().show();
        SingleInstanceInner.getInstance().show();
        SingleInstanceLazy.getInstance().show();
        SingleInstanceLazy.getInstance().show();
    }

}
